package com.xbao.dao;

import com.xbao.model.RoleRuleRel;
import com.xbao.model.Rule;
import com.xbao.model.UserRole;
import com.xbao.model.req.EmpReq;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 */
@Mapper
@CacheConfig(cacheManager = "redisCacheManager", cacheNames = "roleCache")
public interface RoleMapper {
    @Insert("insert into rule(name) values(#{name})")

    public void addRule(Rule rule);


    @Select("select * from role_rule_rel where id=#{id}  ")
    public List<RoleRuleRel> getMyRoles(EmpReq req);

    @CachePut(value = "models", key = "#name")
    public void addRoleRule(RoleRuleRel rel);

    public List<Rule> queryRuleOfRole(Long roleid);

    @Select("select * from rule whereid=#{id}")
    public Rule detailRule(Long id);

    @Delete("delete from rule where id =#{id}")
    @CacheEvict(value = "models", key = "#name")
    public void deleteRUle(Long id);

    @Select("select * from rule_rel where uid=#{uid}")
    @Cacheable(key = "#p0")
    public List<Rule> queryRulesOfUser(Long uid);
    @Select("select * from role_rule_rel where roleid=#{roleid}")
    public List<RoleRuleRel> queryRoleRuleRels(Long roleid);

    public void addUserRoles(List<UserRole> userRoles);

    public void removeUserRoles(Long uid);
}
